<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    console.log("script start");
    function requestData(url) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          console.log("setTimeout");
          resolve(url)
        }, 2000)
      })
    }

    // 1.promis在调用then调度
    // function getData() {
    //   console.log("getData start");
    //   // 这个then得上边resolve才有的，这个then是执行宏任务setTimeout的时候才产生的微任务
    //   requestData('why').then(res => {
    //     console.log("then1-res", res);
    //   })
    //   console.log("getData end");
    // }


    // 2.await/async
    async function getData() {
      console.log("getData start");
      let res = await requestData('why')
      console.log("then1-res:", res);
      console.log("getData end");
    }


    getData()

    console.log("script end");

  </script>

</body>

</html>